/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vanScheduling;

import db.VehicleTypeDAO;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

/**
 *
 * @author user
 */
@ManagedBean
@SessionScoped
public class VehicleType {

    private int id;
    private String name;
    private int numOfSeats;
    private static VehicleType editableVehicleType;

    //<editor-fold desc="Constructors">
    public VehicleType() {
    }

    public VehicleType(int id, String name, int numOfSeats) {
        this.id = id;
        this.name = name;
        this.numOfSeats = numOfSeats;
    }
    //</editor-fold>

    //<editor-fold desc="Getters and Setters">
    public int getId() {
        return id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getNumOfSeats() {
        return numOfSeats;
    }

    public void setNumOfSeats(int numOfSeats) {
        this.numOfSeats = numOfSeats;
    }
    //</editor-fold>

    //<editor-fold desc="Editable VehicleType">
    public void setEditableVehicleType(VehicleType vehicleType) {
        editableVehicleType = vehicleType;
    }

    public VehicleType getEditableVehicleType() {
        return editableVehicleType;
    }

    public String editVehicleType() {
        FacesContext fc = FacesContext.getCurrentInstance();
        setEditableVehicleType((VehicleType) fc.getExternalContext().getRequestMap().get("vehicleType"));
        return "editVehicleType";
    }
    //</editor-fold>

    //<editor-fold desc="CRUD Methods">
    public String addVehicleType() {
        VehicleTypeDAO.addVehicleType(this);
        return "vehicleTypeList";
    }

    public String deleteVehicleType() {
        if (VehicleTypeDAO.deleteVehicleType(this)) {
            return "vehicleTypeList";
        } else {
            return "vehicleTypeDeleteFailure";
        }
    }

    public List<VehicleType> getVehicleTypes() {
        return VehicleTypeDAO.getVehicleTypes();
    }

    public String saveVehicleType() {
        if (VehicleTypeDAO.saveVehicleType(this)) {
            editableVehicleType = null;
            return "vehicleTypeList";
        } else {
            return "vehicleTypeSaveFailure";
        }
    }
    //</editor-fold>

    @Override
    public String toString() {
        return this.name;
    }
}
